<?php

require_once 'Entity.php';

/**
 * Składnik/potrawa zamówienia. 
 *
 * @author Rafał Cupał
 * @author Przemysław Furmańczyk
 */
class OrderMeal extends Entity {
    protected $order = null;
    protected $menuPosition = null;
    
    public function __construct($dataBase) {
        parent::__construct($dataBase, 'orderMeals');
    }
    
    public function getOrderId() {
        return $this->order;
    }
    
    public function setOrderId($newOrderId) {
        $this->order = (int)$newOrderId;
    }
    
    public function getMenuPositionId() {
        return $this->menuPosition;
    }
    
    public function setMenuPositionId($newMenuPositionId) {
        $this->menuPosition = (int)$newMenuPositionId;
    }
    
    public function load($rowData) {
        $this->id = $rowData['id'];
        $this->getRowData($rowData, $this->order, 'order');
        $this->getRowData($rowData, $this->menuPosition, 'menuPosition');
    }
    
    public function save() {
        $rowData = array();
      
        $this->setRowData($rowData, $this->order, 'order');
        $this->setRowData($rowData, $this->menuPosition, 'menuPosition');
        
        if ($this->id > 0) {
            $this->dataBase->update($this->tableName, $rowData, 
                    'id = ' . $this->id);
        }
        else {
            $this->dataBase->insert($this->tableName, $rowData);
            $this->id = $this->dataBase->lastInsertId();
        }
    }
}
